package com.example.FirstBook;

import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.drawerlayout.widget.DrawerLayout;

import com.example.FirstBook.Activity.Food_Nutrition_Activity;
import com.example.FirstBook.Activity.Food_soft_Activity;
import com.example.FirstBook.Activity.food_list_Activity;
import com.example.myapplication.R;

public class MainActivity extends AppCompatActivity {

    private DrawerLayout drawlayout;
    private LinearLayout layout;
    private ListView firstBookListview;
    String ee[] = new String[8];
    ArrayAdapter<String> arrayAdapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main3);
        initView();
        ActionBar actionBar=getSupportActionBar();
        if (actionBar!=null){
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setHomeAsUpIndicator(R.drawable.set);
        }
        init_Data();
    }
/*
初始化数据
 */
public void init_Data(){
    ee[0] = "健康与饮食";
    ee[1] = "注册页面";
    ee[2]="计算器页面";
    ee[3]="猜拳游戏";
    ee[4]="轮播滚动图";
    ee[5]="书籍列表二级联动";
    ee[6]="信息列表展示";
    ee[7]="照片墙效果";
    arrayAdapter = new ArrayAdapter(this, android.R.layout.activity_list_item, android.R.id.text1, ee);
    firstBookListview.setAdapter(arrayAdapter);
}
    /*
    添加自定义菜单
     */
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.first_menue, menu);
        return true;
    }

    /*
    设置菜单点击事件
     */
    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                if (drawlayout.isDrawerOpen(Gravity.LEFT)){
                    drawlayout.closeDrawer(Gravity.LEFT);
                }else {
                    drawlayout.openDrawer(Gravity.LEFT);
                }
                break;
            case R.id.add_item:
                Toast.makeText(this, "暂未设置添加按钮", Toast.LENGTH_SHORT).show();
                break;
            case R.id.remove_item:
                Toast.makeText(this, "暂未设置删除按钮", Toast.LENGTH_SHORT).show();
                break;
            case R.id.find_item:
                Toast.makeText(this, "暂未设置查找按钮", Toast.LENGTH_SHORT).show();
                break;
        }
        return true;
    }
/*
初始化控件
 */
    private void initView() {
        drawlayout = (DrawerLayout) findViewById(R.id.drawlayout);
        layout = (LinearLayout) findViewById(R.id.layout);
        firstBookListview = (ListView) findViewById(R.id.first_book_Listview);
    }
    /*
    点击事件
     */
    public void onClick(View view){
        switch (view.getId()) {
            case R.id.btn_food_list:
                startActivity(new Intent(MainActivity.this, food_list_Activity.class));
                break;
            case R.id.btn_food_nutriction:
                startActivity(new Intent(MainActivity.this, Food_Nutrition_Activity.class));
                break;
            case R.id.btn_food_about:
                startActivity(new Intent(MainActivity.this, Food_soft_Activity.class));
                    break;
        }
    }
}
